package data_structure;

public class leetcode_0112 {
    public boolean hasPathSum(TreeNode root, int targetSum) {
        if(root==null) return false;
        boolean[] flag=new boolean[1];
        dfs(root,targetSum-root.val,flag);
        return flag[0];
    }
    public void dfs(TreeNode node ,int targetSum,boolean[] flag){
        if(targetSum==0&&node.left==null&&node.right==null){
            flag[0]=true;
        }
        if(node.left!=null){
            dfs(node.left,targetSum-node.left.val,flag);

        }
        if(node.right!=null){
            dfs(node.right,targetSum-node.right.val,flag);
        }

    }
}
